import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:syria_sports/core/app_export.dart';
import 'package:syria_sports/data/controllers/exercises_controller.dart';

import '../../../../dialogs/delete_player_confirmation.dart';
import '../models/public_exercise.dart';

class ExerciseItemView extends StatelessWidget {
  final PublicExercise exercise;
  const ExerciseItemView({super.key, required this.exercise});

  @override
  Widget build(BuildContext context) {

    return Card(
      color: Theme.of(context).colorScheme.secondary,
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(exercise.name,style: theme.textTheme.titleMedium),
            Row(
              children: [
                Icon(Icons.group,color: Colors.red,),
                SizedBox(width: 4),
                Text(exercise.targetGroup,style: CustomTextStyles.bodySmallOnPrimary),
              ],
            ),
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text(
                exercise.description,
                overflow: TextOverflow.ellipsis,
                style: theme.textTheme.displaySmall!.copyWith(color: Color(0xffbdbab9)),
                maxLines: 50,
              ),
            ),
            Row(
              children: [
                Text('يبدأ:  ${exercise.fromTime}', style: theme.textTheme.displaySmall!.copyWith(color: Colors.white),),
                SizedBox(width: 4),
                Text('ينتهي: ${exercise.toTime}', style: theme.textTheme.displaySmall!.copyWith(color: Colors.white),),
              ],
            ),
          ],
        ),
      ),
    );
  }
  void showDeleteConfirmation(BuildContext context, PublicExercise exercise) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return DeleteConfirmationDialog(
          playerName: exercise.name,
          titleUser: 'التمرين',
          onConfirm: () {
            ExercisesController.deleteById(exercise.exerciseId??'-1');
            if (kDebugMode) {
              print('تم حذف تمرين ${exercise.name}!');
            }
          },
        );
      },
    );
  }
}
